	/*This sets up two tasks:
	1.  one to convert the floating point data into a native format for the 
	    analog output DACs (12 or 16bit counts).  The CONVERT operation also moves
		the data into a memory buffer that DriverLINX will use in task 2
	2.  the second sets up the interrupt analog output service to generate a 100 Hz sine.
	*/
	
	
	//memset(m_pSR,0,sizeof(DL_ServiceRequest));
	//DL_SetServiceRequestSize(*m_pSR);
	
	// generate some voltage data for the DAC to write
	WORD SampleNum;  // nSamples
	SampleNum = 65535;
	float sinebuf[65535]; //create an array of float for the sine wave
	DWORD i;
	for(i=0;i<(65535);i++)
	{
		sinebuf[i]=(float)sin(i*2*3.14159/(65535))*5;  // 5 volt amplitude, 65535 points per period
	}  

	
    clearBuffers(); //clear any existing memory buffers

	// now allocate buffers to hold our data
	m_pSR->lpBuffers=(DL_BUFFERLIST*)new BYTE[DL_BufferListBytes(1)]; //Create a buffer list for one buffer
	m_pSR->lpBuffers->nBuffers=1; //Only one buffer will be used
	//m_pSR->lpBuffers->notify=NOTIFY;
	m_pSR->lpBuffers->bufferSize=Samples2Bytes(m_deviceNumber,AO,m_logicalChannel,2*SampleNum); //allocate enough bytes for 100 samples
    m_pSR->lpBuffers->BufferAddr[0]=BufAlloc(GBUF_DMA16,m_pSR->lpBuffers->bufferSize); //allocate one 100 point buffer
    
	
	/* now use CONVERT operation to convert volts to counts according to hardware
	   feature of the DAC, e.g. 12 or 16 bit and offset binary, etc. AND to move this
	   data from the sinebuf array to the allocated memory buffer  */
	m_pSR->hWnd=m_hWnd;
	m_pSR->operation=CONVERT; //Use the convert operation to translate float into counts
	m_pSR->device=m_deviceNumber;
	m_pSR->subsystem=AO;
	m_pSR->mode=OTHER;
	m_pSR->channels.nChannels=1;  //only using one channel
	m_pSR->channels.chanGain[0].channel=m_logicalChannel; // Set the appropriate channel in the channel/gain list
	m_pSR->channels.numberFormat=tNATIVE;
	m_pSR->start.typeEvent=DATACONVERT;
	m_pSR->start.u.dataConvert.nSamples = SampleNum; //nSamples to Convert
    m_pSR->start.u.dataConvert.numberFormat=tSINGLE; //the input buffer is of type float
	m_pSR->start.u.dataConvert.scaling=0.0f; //no scaling will be used
	m_pSR->start.u.dataConvert.offset=0.0f; //no offset will be applied
	m_pSR->start.u.dataConvert.wBuffer=0; //put the converted samples into buffer 0
	m_pSR->start.u.dataConvert.lpBuffer=sinebuf; //use the sinebuf array as the input buffer
	m_pSR->start.u.dataConvert.startIndex=0; //start at index 0 for the conversion
	DriverLINX(m_pSR); //execute the conversion
	showMessage(m_pSR); //show any errors

	 //now convert second half of the data.....
	m_pSR->operation=CONVERT; //Use the convert operation to translate float into counts
	m_pSR->start.u.dataConvert.startIndex=32768;  //SampleNum; //start at an offset
	DriverLINX(m_pSR); //execute the conversion
	showMessage(m_pSR); //show any errors
	/*   convert operation is size limited to 2^16 Samples (65535) (WORD).....
       can only do two as the startIndex is also WORD.......convert operation no
	   good if number of samples is larger than WORD * 2.  In which case, need to 
	   allocate multiple buffers, each of which is no larger than 65K Samples.  */

	

	/*Setup the service request for DMA mode analog output
	  Now that data is in the memory buffer, program a paced mode
	  AO task to write this data on the DAC at a requested update rate*/
	
	m_pSR->operation=START;
	m_pSR->device=m_deviceNumber;
	m_pSR->subsystem=AO;
	m_pSR->mode=DMA;
	m_pSR->start.typeEvent=COMMAND;
	m_pSR->channels.nChannels=1;  //only using one channel
	m_pSR->channels.chanGain[0].channel=m_logicalChannel; // Set the appropriate channel in the channel/gain list
	m_pSR->channels.numberFormat=tNATIVE;
	m_pSR->timing.typeEvent=RATEEVENT;
	m_pSR->timing.u.rateEvent.channel=DEFAULTTIMER; //DEFAULTTIMER will pick the appropriate timing channel for a rate event
	m_pSR->timing.u.rateEvent.mode=RATEGEN; //use the rate generator mode to time the waveform
	m_pSR->timing.u.rateEvent.clock=INTERNAL1;
	m_pSR->timing.u.rateEvent.gate=DISABLED; //don't use gating 
	m_pSR->timing.u.rateEvent.period=Sec2Tics(m_deviceNumber,AO,INTERNAL1,0.000015f); //update rate 
	m_pSR->timing.u.rateEvent.pulses=0; //the rate generator will be continuous
	m_pSR->stop.typeEvent=TCEVENT; //Stop automatically
	DriverLINX(m_pSR); //Start the waveform
	showMessage(m_pSR); //show any errors
	//m_stopEn.EnableWindow(TRUE); //Enable the stop button, but disable the others to avoid conflicts
	//m_startEn.EnableWindow(FALSE);
	//m_quitEn.EnableWindow(FALSE);
	UpdateData(FALSE);